package com.michale.admin.mqtt.controller;

import com.michale.admin.mqtt.domain.MqttVo;
import com.michale.admin.mqtt.service.MqttSend;
import com.michale.common.annotation.Anonymous;
import com.michale.common.result.AjaxResult;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Michale
 * @apiNote MQTT协议管理
 */
@Api(tags = "MQTT协议管理")
@RestController
@RequestMapping("/mqtt")
public class MqttController {

    private final MqttSend mqttSend;

    public MqttController(MqttSend mqttSend) {
        this.mqttSend = mqttSend;
    }

    /**
     * 对接硬件设备
     *
     */
    @Anonymous
    @PostMapping("/michale/led")
    public AjaxResult openLed(@RequestBody MqttVo mqttVo ) {
        mqttSend.send(mqttVo.getTopic(), mqttVo.getPayload());
        return new AjaxResult().put("led_status", "open");
    }
}
